package com.topboya.linker.diyview;

import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;

import com.topboya.linker.R;

/**
 * @创建者 CSDN_LQR
 * @描述 自定义圆角的dialog
 */
public class NoDeleteTaskDialog extends DialogFragment {

    private View.OnClickListener close_listener;

    public static NoDeleteTaskDialog newInstance() {

        NoDeleteTaskDialog dialog = new NoDeleteTaskDialog();
        return dialog;
    }

    public void setCloseButtonListener(View.OnClickListener listener) {

        this.close_listener = listener;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {


        LayoutInflater inflaterDl = LayoutInflater.from(getActivity());
        LinearLayout layout = (LinearLayout) inflaterDl.inflate(R.layout.nodelete_task_dialog, null);
        //对话框
        final Dialog dialog = new Dialog(getActivity(),R.style.common_dialog_style);
        dialog.setContentView(layout);
        Window dialogWindow = dialog.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        WindowManager manager= dialog.getWindow().getWindowManager();
        dialogWindow.setGravity(Gravity.CENTER);
//        lp.width = LinearLayout.LayoutParams.MATCH_PARENT; // 宽度
        lp.height =LinearLayout.LayoutParams.WRAP_CONTENT; // 高度
        Display defaultDisplay = manager.getDefaultDisplay();
        lp.width = (int) (defaultDisplay.getWidth() * 0.80);
        // 当Window的Attributes改变时系统会调用此函数,可以直接调用以应用上面对窗口参数的更改,也可以用setAttributes
        // dialog.onWindowAttributesChanged(lp);
        dialogWindow.setAttributes(lp);
        Button btn_close = layout.findViewById(R.id.btn_close);


        if (close_listener != null){

            btn_close.setOnClickListener(close_listener);
        }

        return dialog;

    }

}